/**
 * 定义小时数据模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.sw.reportHistory.reportHourDataManager', ['water.apps.common.report.reportBase',
	                                                                                  'water.common.dateUtil']);
	
	module.controller('reportHourDataManagerController',function($rootScope,$scope,$controller,$dateUtil){

		var control = $controller("commonReportController",{$scope:$scope});
		
		$scope.dataAPIName = "hourListGetter";
		$scope.dataExportAPIName = "exportHourExcel";
		/**
		 * 开始时间
		 */
		$scope.startDate;
		/**
		 * 结束时间
		 */
		$scope.endDate;
		
		/**
		 * 获取查询参数
		 */
		$scope.getQueryObject = function(){
			var parmsStr = $scope.selectedModel.parmToChecksStr;
			var curDate = new Date();
			var curDateStr = $dateUtil.formatDate(curDate,"yyyy-MM-dd");
			
			var timeStr ;
			/**
			 * 如果结束时间是当天的话
			 * 截止到当前小时，因为后端加入了数据留白的功能
			 * 所以如果取一整天的话，不必要的留白会很多
			 * 
			 * 如果不是当天，则取到23:59:59
			 */
			if(curDateStr == $scope.endDate){
				timeStr = curDate.getHours()+":59:59"
			}
			else{
				timeStr = "23:59:59"
			}
			
			var queryObject = {
					"MN":$scope.selectedModel.MN,
					"PARMS":parmsStr,
					"START":$scope.startDate + " 00:00:00",
					"END":$scope.endDate + " " + timeStr
				};
			return queryObject;
		}
		
		/**
		 * 初始化
		 */
		function _init(){
			var endDate = new Date();
			var startDate = $dateUtil.addDay(endDate,-1)
			$scope.startDate = $dateUtil.formatDate(startDate,'yyyy-MM-dd');
			$scope.endDate = $dateUtil.formatDate(endDate,'yyyy-MM-dd');
		}
		
		_init();
		
	});
}(window, angular));	